include Makefile.config

UnstructMG_DIRS = 	utils \
					precond \
					MG \
					iter_solver \
					libs

UnstructMG_ROOT_DIR = $(shell pwd)
UnstructMG_BUILD_DIR = $(UnstructMG_ROOT_DIR)/build

all:
	@ \
	mkdir -p ${UnstructMG_BUILD_DIR}/include; \
	mkdir -p ${UnstructMG_BUILD_DIR}/lib; \
	for i in ${UnstructMG_DIRS}; \
	do \
	  echo "Making $$i ..."; \
	  (cd $$i && $(MAKE) $@) || exit 1; \
	  # cp -fR $$i/*.hpp ${UnstructMG_BUILD_DIR}/include/ ; \
	  echo ""; \
	done
	cp -fR utils/operator.hpp			${UnstructMG_BUILD_DIR}/include/ ;
	cp -fR utils/par_CSRCommPkg.hpp		${UnstructMG_BUILD_DIR}/include/ ;
	cp -fR utils/common.hpp				${UnstructMG_BUILD_DIR}/include/ ;
	cp -fR utils/seq_mv.hpp				${UnstructMG_BUILD_DIR}/include/ ;
	cp -fR utils/par_Vector.hpp			${UnstructMG_BUILD_DIR}/include/ ;
	cp -fR utils/par_CSRMatrix.hpp		${UnstructMG_BUILD_DIR}/include/ ;
	cp -fR utils/direct_solver.hpp		${UnstructMG_BUILD_DIR}/include/ ;
	cp -fR precond/*.hpp				${UnstructMG_BUILD_DIR}/include/ ;
	cp -fR MG/*.hpp						${UnstructMG_BUILD_DIR}/include/ ;
	cp -fR iter_solver/*.hpp			${UnstructMG_BUILD_DIR}/include/ ;
	cp -fR UnstructMG.hpp ${UnstructMG_BUILD_DIR}/include/ ;
	cp -fR libs/*.so ${UnstructMG_BUILD_DIR}/lib
	cd test && $(MAKE) $@

.PHONY: clean

clean : 
	@ \
	rm -rf $(UnstructMG_BUILD_DIR); \
	for i in ${UnstructMG_DIRS} ; \
	do \
	  if [ -f $$i/Makefile ]; \
	  then \
	    echo "Cleaning $$i ..."; \
	    (cd $$i && $(MAKE) $@) || exit 1; \
	  fi; \
	done
	cd test && $(MAKE) $@
